package com.school.revervationSys.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.school.revervationSys.dto.IdDto;
import com.school.revervationSys.dto.KnowledgeNoticeDto;
import com.school.revervationSys.dto.ReverVationDto;
import com.school.revervationSys.entity.KnowledgeNotice;
import com.school.revervationSys.entity.Revervation;
import com.school.revervationSys.service.KnowledgeNoticeService;
import com.school.revervationSys.utils.BaseResponse;
import com.school.revervationSys.utils.ErrorCode;
import com.school.revervationSys.utils.ResultUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/knowledgeNotice")
public class KnowledgeNoticeController {

    @Autowired
    private KnowledgeNoticeService knowledgeNoticeService;


    @PostMapping("/addRevervation")
    public BaseResponse addRevervation(@RequestBody KnowledgeNotice knowledgeNotice){

        boolean b = knowledgeNoticeService.addknowledgeNotice(knowledgeNotice);
        if(b){
            return ResultUtils.success("新增成功");
        }
        return ResultUtils.error(ErrorCode.OPERATION_FAILED,"操作失败");
    }
    @PostMapping("/updateRevervation")
    public BaseResponse updateRevervation(@RequestBody KnowledgeNotice knowledgeNotice){

        boolean b = knowledgeNoticeService.updateknowledgeNotice(knowledgeNotice);
        if(b){
            return ResultUtils.success("修改成功");
        }
        return ResultUtils.error(ErrorCode.OPERATION_FAILED,"修改失败");
    }

    @GetMapping("/delKnowledgeNotice")
    public BaseResponse delKnowledgeNotice(Integer knowledgeNoticeId){

        boolean b = knowledgeNoticeService.delete(knowledgeNoticeId);
        if(b){
            return ResultUtils.success("删除成功");
        }
        return ResultUtils.error(ErrorCode.OPERATION_FAILED,"删除失败");
    }
    @PostMapping("/batchKnowledgeNotice")
    public BaseResponse batchDelete(@RequestBody IdDto param){

        boolean b = knowledgeNoticeService.batchDelete(param.getIds());
        if(b){
            return ResultUtils.success("批量删除成功");
        }
        return ResultUtils.error(ErrorCode.OPERATION_FAILED,"批量删除失败");
    }

    @GetMapping("/knowledgeNoticeInfo")
    public BaseResponse  knowledgeNoticeInfo(@RequestParam String id){

        return ResultUtils.success(knowledgeNoticeService.knowledgeNoticeInfo(id));
    }
    @PostMapping("/knowledgeNoticeList")
    public BaseResponse knowledgeNoticeList(@RequestBody KnowledgeNoticeDto param){
        PageHelper.startPage(param.getPageNo(),param.getPageSize());
        List<KnowledgeNotice> revervations = knowledgeNoticeService.knowledgeNoticeList(param.getTitle());
        PageInfo<KnowledgeNotice> revervationPageInfo = new PageInfo<>(revervations);
        return ResultUtils.success(revervationPageInfo);
    }

}
